package com.xq.jltx.utils;

import android.util.SparseArray;
import android.view.View;

/**
 * @author jltxseo
 *         Created by junlintianxia on 2016/07/20.
 *         通过模板知识产生复用Adapter里面的子View的辅助类
 */
public class ViewHolderUtils {

    public static <T extends View> T get(View view,int id){
        SparseArray<View> viewHolders = (SparseArray<View>)view.getTag();
        if(viewHolders == null){
            viewHolders = new SparseArray<View>();
            view.setTag(viewHolders);
        }

        View childView = viewHolders.get(id);
        if(null == childView){
            childView = view.findViewById(id);
            viewHolders.put(id,childView);
        }
        return (T) childView;
    }

}
